home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / tcpdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-30  |  1.9 KB  |  88 lines

  1. /* TCP header tracing routines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include <stdio.h>
  5. #include "global.h"
  6. #include "mbuf.h"
  7. #include "netuser.h"
  8. #include "internet.h"
  9. #include "tcp.h"
  10. #include "ip.h"
  11. #include "trace.h"
  12.  
  13. #ifdef TNOS_68K
  14. #define fprintf traceprintf
  15. #endif
  16.  
  17. /* TCP segment header flags */
  18. static char *Tcpflags[] = {
  19.     "FIN",    /* 0x01 */
  20.     "SYN",    /* 0x02 */
  21.     "RST",    /* 0x04 */
  22.     "PSH",    /* 0x08 */
  23.     "ACK",    /* 0x10 */
  24.     "URG",    /* 0x20 */
  25.     "CE"    /* 0x40 */
  26. };
  27.  
  28. /* Dump a TCP segment header. Assumed to be in network byte order */
  29. void
  30. tcp_dump(fp,bpp,source,dest,check)
  31. FILE *fp;
  32. struct mbuf **bpp;
  33. int32 source,dest;    /* IP source and dest addresses */
  34. int check;        /* 0 if checksum test is to be bypassed */
  35. {
  36.     struct tcp seg;
  37.     struct pseudo_header ph;
  38.     int16 csum;
  39.     int16 dlen;
  40.  
  41.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  42.         return;
  43.  
  44.     /* Verify checksum */
  45.     ph.source = source;
  46.     ph.dest = dest;
  47.     ph.protocol = TCP_PTCL;
  48.     ph.length = len_p(*bpp);
  49.     csum = cksum(&ph,*bpp,ph.length);
  50.  
  51.     ntohtcp(&seg,bpp);
  52.  
  53.     fprintf(fp,"TCP: %u->%u Seq x%lx",seg.source,seg.dest,seg.seq,seg.ack);
  54.     if(seg.flags.ack)
  55.         fprintf(fp," Ack x%lx",seg.ack);
  56.     if(seg.flags.congest)
  57.         fprintf(fp," %s",Tcpflags[6]);
  58.     if(seg.flags.urg)
  59.         fprintf(fp," %s",Tcpflags[5]);
  60.     if(seg.flags.ack)
  61.         fprintf(fp," %s",Tcpflags[4]);
  62.     if(seg.flags.psh)
  63.         fprintf(fp," %s",Tcpflags[3]);
  64.     if(seg.flags.rst)
  65.         fprintf(fp," %s",Tcpflags[2]);
  66.     if(seg.flags.syn)
  67.         fprintf(fp," %s",Tcpflags[1]);
  68.     if(seg.flags.fin)
  69.         fprintf(fp," %s",Tcpflags[0]);
  70.  
  71.     fprintf(fp," Wnd %u",seg.wnd);
  72.     if(seg.flags.urg)
  73.         fprintf(fp," UP x%x",seg.up);
  74.     /* Print options, if any */
  75.     if(seg.mss != 0)
  76.         fprintf(fp," MSS %u",seg.mss);
  77.     if((dlen = len_p(*bpp)) != 0)
  78.         fprintf(fp," Data %u",dlen);
  79.     if(check && csum != 0)
  80.         fprintf(fp," CHECKSUM ERROR (%u)",csum);
  81. #ifdef TNOS_68K
  82.     fprintf (fp, "\n");
  83. #else
  84.     putc('\n',fp);
  85. #endif
  86. }
  87.  
  88.